package com.zlx.mall.biz.access.controller;


import com.zlx.mall.basic.web.model.BaseRequest;
import com.zlx.mall.basic.web.model.BaseResponse;
import com.zlx.mall.biz.access.model.LoginRequest;
import com.zlx.mall.biz.access.service.IUserLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author xiatian
 * @Date 2024/5/25 星期六 10:38
 * @注释 用户登录
 */
@Slf4j
@RestController
@RequestMapping(method = RequestMethod.POST)
public class UserLoginController {
    @Autowired
    private IUserLoginService userLoginService;


    @PostMapping("/api/user/login")
    public BaseResponse login(BaseRequest request) {
        return userLoginService.login(request.toObjectAndValidate(LoginRequest.class));
    }

    @PostMapping("/api/user/login/verify")
    public BaseResponse loginVerify(BaseRequest request) {
        return BaseResponse.success(userLoginService.loginVerify(request.toObjectAndValidate(LoginRequest.class)));
    }

    @PostMapping("/api/user/logout")
    public BaseResponse logout(BaseRequest request) {
        userLoginService.logout(request);
        return BaseResponse.success();
    }

    @GetMapping("/api/user/afterSalesMobile")
    public BaseResponse afterSalesMobile(BaseRequest request) {
        return BaseResponse.success(userLoginService.afterSalesMobile());
    }

    @GetMapping("/api/user/login/fast")
    public BaseResponse loginFast(BaseRequest request) {
        return BaseResponse.success(userLoginService.loginFast(request.asText("/code")));
    }

}
